package com.ruoyi.web.controller.app;

import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.core.page.ResponseResult;
import com.ruoyi.system.domain.SysNotice;
import com.ruoyi.system.service.ISysNoticeService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
//@Api(tags = "用户端:资讯相关接口")
@RestController
@RequestMapping("public/notice")
public class NoticeController extends AppController {
    @Resource
    private ISysNoticeService noticeService;


    @ApiOperation(value = "资讯列表")
    @GetMapping("list")
    public ResponseResult<SysNotice> list(String type) {
        SysNotice sysNotice = new SysNotice();
        sysNotice.setNoticeType(type);
        List<SysNotice> sysNotices = noticeService.selectNoticeList(sysNotice);

        if (StrUtil.equals(type, "2") && sysNotices.size() == 1) {
            SysNotice sysNotice1 = sysNotices.get(0);
            sysNotice1.setNoticeId(0L);
            sysNotices.add(sysNotice1);
        }


        return this.setSuccessResult(sysNotices);
    }

    @ApiOperation(value = "资讯列表")
    @GetMapping("getNotice")
    public ResponseResult<SysNotice> getNotice() {
        SysNotice sysNotice = new SysNotice();
        sysNotice.setNoticeType("1");
        List<SysNotice> sysNotices = noticeService.selectNoticeList(sysNotice);

        if (sysNotices.size() >= 1) {
            return this.setSuccessResult(sysNotices.get(0));
        }
        return this.setSuccessResult();
    }


}
